import { defineStore } from 'pinia';

interface project {
  name: string;
  desc: string;

  [key: string]: any;
}

export const useCurrentProjectStore = defineStore('current-project', {
  state: () => ({
    project_id: 0,
    blockVisible: false,
  }),
  getters: {},
  actions: {
    setCurrentProject(project_id: number): void {
      this.project_id = project_id;
    },
    setBlockVisible(isOpen: boolean): void {
      this.blockVisible = isOpen;
    },
    resetProject(data: project): void {
      if (!data) {
        return;
      }
      // const memberNames = []
      // for (const member of data.members){
      //     memberNames.push(member.username)
      // }
      // const projectData = JSON.parse(JSON.stringify(data))
      // projectData.memberNames = memberNames.join(';')
      // this.project = projectData
    },

    persist: {
      enabled: true, //不单独设置则为默认全开
      strategies: [
        {
          // 自定义存储方式，默认sessionStorage
          storage: sessionStorage,
          // 指定要持久化的数据
          paths: ['project_id'],
        },
      ],
    },
  },
});
